//---------------------------------------------------------------------------------
// Copyright (c) 2008 Metaphor Game Engine Project
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
//     1. The origin of this software must not be misrepresented; you must not
//        claim that you wrote the original software. If you use this software
//        in a product, an acknowledgment in the product documentation would be
//        appreciated but is not required.
//
//     2. Altered source versions must be plainly marked as such, and must not be
//        misrepresented as being the original software.
//
//     3. This notice may not be removed or altered from any source
//        distribution.
//---------------------------------------------------------------------------------

#include "BindingsManager.h"

#include "HIDManager.h"

std::map<OIS::KeyCode, std::string> gKeyCodeToString;
std::map<std::string, OIS::KeyCode> gStringToKeyCode;

bool gKeyCodesInitialized = false;

#define ADD_KEYCODE_MAPPING(keycode, str)       \
  gKeyCodeToString[OIS::##keycode] = str;              \
  gStringToKeyCode[str] = OIS::##keycode;

void EnsureKeyCodesInitialized()
{
  if (gKeyCodesInitialized == true)
  {
    return;
  }

  ADD_KEYCODE_MAPPING(  KC_UNASSIGNED       , "UNASSIGNED"     )
    ADD_KEYCODE_MAPPING(  KC_ESCAPE           , "ESCAPE"         )
    ADD_KEYCODE_MAPPING(  KC_1                , "1"              ) 
    ADD_KEYCODE_MAPPING(  KC_2                , "2"              ) 
    ADD_KEYCODE_MAPPING(  KC_3                , "3"              )
    ADD_KEYCODE_MAPPING(  KC_4                , "4"              )
    ADD_KEYCODE_MAPPING(  KC_5                , "5"              )
    ADD_KEYCODE_MAPPING(  KC_6                , "6"              )
    ADD_KEYCODE_MAPPING(  KC_7                , "7"              )
    ADD_KEYCODE_MAPPING(  KC_8                , "8"              )
    ADD_KEYCODE_MAPPING(  KC_9                , "9"              )
    ADD_KEYCODE_MAPPING(  KC_0                , "0"              )
    ADD_KEYCODE_MAPPING(  KC_MINUS            , "MINUS"          )
    ADD_KEYCODE_MAPPING(  KC_EQUALS           , "EQUALS"         )
    ADD_KEYCODE_MAPPING(  KC_BACK             , "BACK"           )
    ADD_KEYCODE_MAPPING(  KC_TAB              , "TAB"            )
    ADD_KEYCODE_MAPPING(  KC_Q                , "Q"              )
    ADD_KEYCODE_MAPPING(  KC_W                , "W"              )
    ADD_KEYCODE_MAPPING(  KC_E                , "E"              )
    ADD_KEYCODE_MAPPING(  KC_R                , "R"              )
    ADD_KEYCODE_MAPPING(  KC_T                , "T"              )
    ADD_KEYCODE_MAPPING(  KC_Y                , "Y"              )
    ADD_KEYCODE_MAPPING(  KC_U                , "U"              )
    ADD_KEYCODE_MAPPING(  KC_I                , "I"              )
    ADD_KEYCODE_MAPPING(  KC_O                , "O"              )
    ADD_KEYCODE_MAPPING(  KC_P                , "P"              )
    ADD_KEYCODE_MAPPING(  KC_LBRACKET         , "LBRACKET"       )
    ADD_KEYCODE_MAPPING(  KC_RBRACKET         , "RBRACKET"       )
    ADD_KEYCODE_MAPPING(  KC_RETURN           , "RETURN"         )
    ADD_KEYCODE_MAPPING(  KC_LCONTROL         , "LCONTROL"       )
    ADD_KEYCODE_MAPPING(  KC_A                , "A"              )
    ADD_KEYCODE_MAPPING(  KC_S                , "S"              )
    ADD_KEYCODE_MAPPING(  KC_D                , "D"              )
    ADD_KEYCODE_MAPPING(  KC_F                , "F"              )
    ADD_KEYCODE_MAPPING(  KC_G                , "G"              )
    ADD_KEYCODE_MAPPING(  KC_H                , "H"              )
    ADD_KEYCODE_MAPPING(  KC_J                , "J"              )
    ADD_KEYCODE_MAPPING(  KC_K                , "K"              )
    ADD_KEYCODE_MAPPING(  KC_L                , "L"              )
    ADD_KEYCODE_MAPPING(  KC_SEMICOLON        , "SEMICOLON"      )
    ADD_KEYCODE_MAPPING(  KC_APOSTROPHE       , "APOSTROPHE"     )
    ADD_KEYCODE_MAPPING(  KC_GRAVE            , "GRAVE"          )
    ADD_KEYCODE_MAPPING(  KC_LSHIFT           , "LSHIFT"         )
    ADD_KEYCODE_MAPPING(  KC_BACKSLASH        , "BACKSLASH"      )
    ADD_KEYCODE_MAPPING(  KC_Z                , "Z"              )
    ADD_KEYCODE_MAPPING(  KC_X                , "X"              )
    ADD_KEYCODE_MAPPING(  KC_C                , "C"              )
    ADD_KEYCODE_MAPPING(  KC_V                , "V"              )
    ADD_KEYCODE_MAPPING(  KC_B                , "B"              )
    ADD_KEYCODE_MAPPING(  KC_N                , "N"              )
    ADD_KEYCODE_MAPPING(  KC_M                , "M"              )
    ADD_KEYCODE_MAPPING(  KC_COMMA            , "COMMA"          )
    ADD_KEYCODE_MAPPING(  KC_PERIOD           , "PERIOD"         )
    ADD_KEYCODE_MAPPING(  KC_SLASH            , "SLASH"          )
    ADD_KEYCODE_MAPPING(  KC_RSHIFT           , "RSHIFT"         )
    ADD_KEYCODE_MAPPING(  KC_MULTIPLY         , "MULTIPLY"       )
    ADD_KEYCODE_MAPPING(  KC_LMENU            , "LMENU"          )
    ADD_KEYCODE_MAPPING(  KC_SPACE            , "SPACE"          )
    ADD_KEYCODE_MAPPING(  KC_CAPITAL          , "CAPITAL"        )
    ADD_KEYCODE_MAPPING(  KC_F1               , "F1"             )
    ADD_KEYCODE_MAPPING(  KC_F2               , "F2"             )
    ADD_KEYCODE_MAPPING(  KC_F3               , "F3"             )
    ADD_KEYCODE_MAPPING(  KC_F4               , "F4"             )
    ADD_KEYCODE_MAPPING(  KC_F5               , "F5"             )
    ADD_KEYCODE_MAPPING(  KC_F6               , "F6"             )
    ADD_KEYCODE_MAPPING(  KC_F7               , "F7"             )
    ADD_KEYCODE_MAPPING(  KC_F8               , "F8"             )
    ADD_KEYCODE_MAPPING(  KC_F9               , "F9"             )
    ADD_KEYCODE_MAPPING(  KC_F10              , "F10"            )
    ADD_KEYCODE_MAPPING(  KC_NUMLOCK          , "NUMLOCK"        )
    ADD_KEYCODE_MAPPING(  KC_SCROLL           , "SCROLL"         )
    ADD_KEYCODE_MAPPING(  KC_NUMPAD7          , "NUMPAD7"        )
    ADD_KEYCODE_MAPPING(  KC_NUMPAD8          , "NUMPAD8"        )
    ADD_KEYCODE_MAPPING(  KC_NUMPAD9          , "NUMPAD9"        )
    ADD_KEYCODE_MAPPING(  KC_SUBTRACT         , "SUBTRACT"       )
    ADD_KEYCODE_MAPPING(  KC_NUMPAD4          , "NUMPAD4"        )
    ADD_KEYCODE_MAPPING(  KC_NUMPAD5          , "NUMPAD5"        )
    ADD_KEYCODE_MAPPING(  KC_NUMPAD6          , "NUMPAD6"        )
    ADD_KEYCODE_MAPPING(  KC_ADD              , "ADD"            )
    ADD_KEYCODE_MAPPING(  KC_NUMPAD1          , "NUMPAD1"        )
    ADD_KEYCODE_MAPPING(  KC_NUMPAD2          , "NUMPAD2"        )
    ADD_KEYCODE_MAPPING(  KC_NUMPAD3          , "NUMPAD3"        )
    ADD_KEYCODE_MAPPING(  KC_NUMPAD0          , "NUMPAD0"        )
    ADD_KEYCODE_MAPPING(  KC_DECIMAL          , "DECIMAL"        )
    ADD_KEYCODE_MAPPING(  KC_OEM_102          , "OEM_102"        )
    ADD_KEYCODE_MAPPING(  KC_F11              , "F11"            )
    ADD_KEYCODE_MAPPING(  KC_F12              , "F12"            )
    ADD_KEYCODE_MAPPING(  KC_F13              , "F13"            )
    ADD_KEYCODE_MAPPING(  KC_F14              , "F14"            )
    ADD_KEYCODE_MAPPING(  KC_F15              , "F15"            )
    ADD_KEYCODE_MAPPING(  KC_KANA             , "KANA"           )
    ADD_KEYCODE_MAPPING(  KC_ABNT_C1          , "ABNT_C1"        )
    ADD_KEYCODE_MAPPING(  KC_CONVERT          , "CONVERT"        )
    ADD_KEYCODE_MAPPING(  KC_NOCONVERT        , "NOCONVERT"      )
    ADD_KEYCODE_MAPPING(  KC_YEN              , "YEN"            )
    ADD_KEYCODE_MAPPING(  KC_ABNT_C2          , "ABNT_C2"        )
    ADD_KEYCODE_MAPPING(  KC_NUMPADEQUALS     , "NUMPADEQUALS"   )
    ADD_KEYCODE_MAPPING(  KC_PREVTRACK        , "PREVTRACK"      )
    ADD_KEYCODE_MAPPING(  KC_AT               , "AT"             )
    ADD_KEYCODE_MAPPING(  KC_COLON            , "COLON"          )
    ADD_KEYCODE_MAPPING(  KC_UNDERLINE        , "UNDERLINE"      )
    ADD_KEYCODE_MAPPING(  KC_KANJI            , "KANJI"          )
    ADD_KEYCODE_MAPPING(  KC_STOP             , "STOP"           )
    ADD_KEYCODE_MAPPING(  KC_AX               , "AX"             )
    ADD_KEYCODE_MAPPING(  KC_UNLABELED        , "UNLABELED"      )
    ADD_KEYCODE_MAPPING(  KC_NEXTTRACK        , "NEXTTRACK"      )
    ADD_KEYCODE_MAPPING(  KC_NUMPADENTER      , "NUMPADENTER"    )
    ADD_KEYCODE_MAPPING(  KC_RCONTROL         , "RCONTROL"       )
    ADD_KEYCODE_MAPPING(  KC_MUTE             , "MUTE"           )
    ADD_KEYCODE_MAPPING(  KC_CALCULATOR       , "CALCULATOR"     )
    ADD_KEYCODE_MAPPING(  KC_PLAYPAUSE        , "PLAYPAUSE"      )
    ADD_KEYCODE_MAPPING(  KC_MEDIASTOP        , "MEDIASTOP"      )
    ADD_KEYCODE_MAPPING(  KC_VOLUMEDOWN       , "VOLUMEDOWN"     )
    ADD_KEYCODE_MAPPING(  KC_VOLUMEUP         , "VOLUMEUP"       )
    ADD_KEYCODE_MAPPING(  KC_WEBHOME          , "WEBHOME"        )
    ADD_KEYCODE_MAPPING(  KC_NUMPADCOMMA      , "NUMPADCOMMA"    )
    ADD_KEYCODE_MAPPING(  KC_DIVIDE           , "DIVIDE"         )
    ADD_KEYCODE_MAPPING(  KC_SYSRQ            , "SYSRQ"          )
    ADD_KEYCODE_MAPPING(  KC_RMENU            , "RMENU"          )
    ADD_KEYCODE_MAPPING(  KC_PAUSE            , "PAUSE"          )
    ADD_KEYCODE_MAPPING(  KC_HOME             , "HOME"           )
    ADD_KEYCODE_MAPPING(  KC_UP               , "UP"             )
    ADD_KEYCODE_MAPPING(  KC_PGUP             , "PAGEUP"         )
    ADD_KEYCODE_MAPPING(  KC_LEFT             , "LEFT"           )
    ADD_KEYCODE_MAPPING(  KC_RIGHT            , "RIGHT"          )
    ADD_KEYCODE_MAPPING(  KC_END              , "END"            )
    ADD_KEYCODE_MAPPING(  KC_DOWN             , "DOWN"           )
    ADD_KEYCODE_MAPPING(  KC_PGDOWN           , "PAGEDOWN"       )
    ADD_KEYCODE_MAPPING(  KC_INSERT           , "INSERT"         )
    ADD_KEYCODE_MAPPING(  KC_DELETE           , "DELETE"         )
    ADD_KEYCODE_MAPPING(  KC_LWIN             , "LWIN"           )
    ADD_KEYCODE_MAPPING(  KC_RWIN             , "RWIN"           )
    ADD_KEYCODE_MAPPING(  KC_APPS             , "APPS"           )
    ADD_KEYCODE_MAPPING(  KC_POWER            , "POWER"          )
    ADD_KEYCODE_MAPPING(  KC_SLEEP            , "SLEEP"          )
    ADD_KEYCODE_MAPPING(  KC_WAKE             , "WAKE"           )
    ADD_KEYCODE_MAPPING(  KC_WEBSEARCH        , "WEBSEARCH"      )
    ADD_KEYCODE_MAPPING(  KC_WEBFAVORITES     , "WEBFAVORITES"   )
    ADD_KEYCODE_MAPPING(  KC_WEBREFRESH       , "WEBREFRESH"     )
    ADD_KEYCODE_MAPPING(  KC_WEBSTOP          , "WEBSTOP"        )
    ADD_KEYCODE_MAPPING(  KC_WEBFORWARD       , "WEBFORWARD"     )
    ADD_KEYCODE_MAPPING(  KC_WEBBACK          , "WEBBACK"        )
    ADD_KEYCODE_MAPPING(  KC_MYCOMPUTER       , "MYCOMPUTER"     )
    ADD_KEYCODE_MAPPING(  KC_MAIL             , "MAIL"           )
    ADD_KEYCODE_MAPPING(  KC_MEDIASELECT      , "MEDIASELECT"    )

    gKeyCodesInitialized = true;
}

#undef ADD_KEYCODE_MAPPING
}
